<?php
namespace app\admin\controller;
use app\admin\controller\Base;
use think\Db;
class Notice extends Base
{
    public function index()
    {
        $gonggao = Db('notice')->order('update_time desc')->paginate(10);
        $this->assign('gonggao',$gonggao);
        return view();
    }
    public function add_notice()
    {
        if(request()->isAjax()){
            $shujv = input('post.');
            $shujv['create_time'] = time();
            $shujv['update_time'] = time();
            $result = Db::name('notice')->insert($shujv);
            exit($result);
        }
        return view();
    }
    public function edit_notice()
    {
        if(request()->isAjax()){
            $id = input('post.id');
            $shujv = input('post.');
            $shujv['update_time'] = time();
            $result = Db::name('notice')->where(array('id' => $id))->update($shujv);
            if ($result === false) {
                exit(json_encode(array('status' => 'n', 'info' => '数据修改失败!')));
            } else {
                exit(json_encode(array('status' => 'y', 'info' => '数据修改成功!')));
            }
        }else{
            $id = input('id');
            $notice  = Db::name('notice')->where(array('id'=>$id))->find();
        }
        $this->assign('notice',$notice);
        return view();
    }
    public function  del_notice(){
        $id = input('post.id');
        $result = Db::name('notice')->where(array('id'=>$id))->delete($id);
    }
}